package com.example.cn.stock.controller;

import com.example.cn.stock.service.StockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RefreshScope
@RequestMapping("/stock")
public class StockController {
    @Value("${user.name}")
    private String name;
    @Value("${user.age}")
    private Integer age;
    @Autowired
    StockService stockService;

    @RequestMapping("/info")
    public String info(){
        return "姓名："+name+"，年龄："+age;
    }
    @RequestMapping("/reduceStock")
    public void reduceStock(@RequestParam("productId") Integer productId) {
        stockService.reduceStock(productId);
    }

    @RequestMapping("/readStock")
    public String readStock(){
        System.out.println("网关测试：stock服务");
        return "网关测试：stock服务";
    }

}